import config from '@/config/config.js';
import MD5 from 'js-md5';

export default {
	uploadFile(tempfile) {
		let timestamp = new Date().getTime();
		let param = `ApiRequest{appId=${config.appId},appKey=${config.appKey},timeStamp=${timestamp}}`;
		let tokenStr = MD5(param);
		let fileUrl = `${config.apiBaseUrl}/file/api/uploadImage?appId=${config.appId}&timeStamp=${timestamp}&token=${tokenStr}`;
		return new Promise((resolve, reject) => {
			uni.uploadFile({
				url: fileUrl, 
				filePath: tempfile,
				name: 'file',
				formData: {},
				success: (uploadFileRes) => {
					console.log("imageFile.js--->", uploadFileRes.data);
					resolve(JSON.parse(uploadFileRes.data))
				},
				fail(err) {
					console.log("文件上传错误：", err);
					resolve(JSON.parse(uploadFileRes.data))
				},
				fail(err) {
					console.log("文件上传错误：", err);
				}
			});
		})
	}
}